package com.frcdi.qms.web.controller.equipment;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.equipment.domain.EquipmentRange;
import com.frcdi.qms.equipment.service.IEquipmentRangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备有效量程Controller
 *
 * @author cell
 * @date 2023-10-10
 */
@Api(tags = "设备有效量程")
@RestController
@RequestMapping("/equipment/range")
public class EquipmentRangeController extends BaseController
{
    @Autowired
    private IEquipmentRangeService equipmentRangeService;

    /**
     * 查询设备有效量程列表
     */
    @ApiOperation("查询设备有效量程列表")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentRange equipmentRange)
    {
        startPage();
        List<EquipmentRange> list = equipmentRangeService.selectEquipmentRangeList(equipmentRange);
        return getDataTable(list);
    }

    /**
     * 导出设备有效量程列表
     */
    @ApiOperation("导出设备有效量程列表")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentRange equipmentRange)
    {
        List<EquipmentRange> list = equipmentRangeService.selectEquipmentRangeList(equipmentRange);
        ExcelUtil<EquipmentRange> util = new ExcelUtil<EquipmentRange>(EquipmentRange.class);
        util.exportExcel(response, list, "设备有效量程数据");
    }

    /**
     * 获取设备有效量程详细信息
     */
    @ApiOperation("获取设备有效量程详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @GetMapping(value = "/{rangeId}")
    public AjaxResult getInfo(@PathVariable("rangeId") Long rangeId)
    {
        return success(equipmentRangeService.selectEquipmentRangeByRangeId(rangeId));
    }

    /**
     * 新增设备有效量程
     */
    @ApiOperation("新增设备有效量程")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentRange equipmentRange)
    {
        equipmentRange.setCreateBy(getUsername());
        return toAjax(equipmentRangeService.insertEquipmentRange(equipmentRange));
    }

    /**
     * 修改设备有效量程
     */
    @ApiOperation("修改设备有效量程")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentRange equipmentRange)
    {
        equipmentRange.setUpdateBy(getUsername());
        return toAjax(equipmentRangeService.updateEquipmentRange(equipmentRange));
    }

    /**
     * 删除设备有效量程
     */
    @ApiOperation("删除设备有效量程")
    @PreAuthorize("@ss.hasPermi('equipment:equipmentBase:edit')")
	@DeleteMapping("/{rangeIds}")
    public AjaxResult remove(@PathVariable Long[] rangeIds)
    {
        return toAjax(equipmentRangeService.deleteEquipmentRangeByRangeIds(rangeIds));
    }
}
